﻿using System;
using System.Collections.Generic;
using System.Text;
using HAVNet.Core;


namespace HAVNet.Intros.AST
{
    public class ASTMemberDeclCtor : ASTMemberDeclClass
    {
        ASTFormalParamList  _fpl        = null;
        ASTArguments        _arguments  = null;

        public string       ident       { get; set; }
        public ASTFormalParamList fpl   { get { if (null == _fpl) _fpl = new ASTFormalParamList(); return _fpl; } }
        public bool         hasBaseCall { get; set; }
        public bool         hasThisCall { get; set; }
        public ASTArguments arguments   { get { if (null == _arguments) _arguments = new ASTArguments(); return _arguments; } }
        public ASTBlock     block       { get; set; }

        public ASTMemberDeclCtor ()
        {
            hasBaseCall = false;
            hasThisCall = false;
        }

        public override string ToString ()
        {
            //  constructorsMod     =
            //      publicMod       |
            //      protectedMod    |
            //      internalMod     |
            //      privateMod      |
            //      unsafeMod       |
            //      externMod       ,

            //  staticConstrMod     =
            //      externMod       |
            //      staticMod       ,

            string sAttrs = ((null == _attrGroups) ? "" : _attrGroups.ToString() + Environment.NewLine);

            string mods = "";

            if (Mods.has(modifiers, Mods.publicMod      )) mods += "public ";
            if (Mods.has(modifiers, Mods.protectedMod   )) mods += "protected ";
            if (Mods.has(modifiers, Mods.internalMod    )) mods += "internal ";
            if (Mods.has(modifiers, Mods.privateMod     )) mods += "private ";
            if (Mods.has(modifiers, Mods.staticMod      )) mods += "static ";
            if (Mods.has(modifiers, Mods.newMod         )) mods += "unsafe ";
            if (Mods.has(modifiers, Mods.externMod      )) mods += "extern ";

            string sBlock           = block == null ? ";" : block.ToString();
            string sThisOrBaseCall  = "";

            if (hasBaseCall || hasThisCall)
            {
                if (hasBaseCall)
                    sThisOrBaseCall += " : base (";
                else if (hasThisCall)
                    sThisOrBaseCall += " : this (";

                sThisOrBaseCall += Lazy.toStringNN (_arguments, "");
                sThisOrBaseCall += ")";
            }

            return
                sAttrs  +
                mods    +
                ident   +
                " (" + Lazy.toStringNN (_fpl, "") + ") "            +
                sThisOrBaseCall + Environment.NewLine   +
                sBlock + Environment.NewLine;
        }
    }
}
